
clear all 

//define folder global here

gl Inputs "$folder\1_Inputs"
gl Intermediate "$folder\2_Intermediate"
gl Outputs "$folder\3_Outputs"

********************************************************************************
********************************************************************************
**# TABLE G.4

*** PREPARE NYC DATA
use "${Inputs}\NY_rf_placebo.dta", clear 

	replace outcome = "earn12" if outcome=="EARNQ-9-12"
	replace outcome = "earn8" if outcome=="EARNQ-1-8"
	replace outcome = "eshu1" if outcome=="ESHUY-1"
	replace outcome = "home1" if outcome=="HOMEY-1"
	replace outcome = "move2" if outcome=="MOVEY-1-2"
	replace outcome = "povr2" if outcome=="POVY-1-2"
	replace outcome = "fem" if outcome=="FEMALE"
	replace outcome = "blac" if outcome=="BLACK"
	replace outcome = "hisp" if outcome=="HISP"
	replace outcome = "adda" if outcome=="RENTOWED"
	replace outcome = "nopr" if outcome=="NOPRIOR"
	
	reshape wide beta se N, i(outcome) j(specification) string 
 
	gen pvalue=2*(1-normal(abs(betaRF / seRF))) 

	gen 	stars = "***" if pvalue < 0.01
	replace stars = "**" if pvalue < 0.05 & mi(stars)
	replace stars = "*" if pvalue < 0.1 & mi(stars)

	gen 	numcoef = string(betaRF, "%12.4fc") + stars
	replace numcoef = string(betaRF, "%12.1fc") + stars if regexm(outcome, "earn|rent")

	gen 	numse = "(" + string(seRF, "%12.4fc") + ")"
	replace numse = "(" + string(seRF, "%12.1fc") + ")" if regexm(outcome, "earn|rent")

	gen 	nummean = string(betaMEANSD, "%12.4fc")
	replace	nummean = string(betaMEANSD, "%12.1fc") if regexm(outcome, "earn|rent")

	gen 	nummse = "(" + string(seMEANSD, "%12.4fc") + ")"
	replace	nummse = "(" + string(seMEANSD, "%12.1fc") + ")" if regexm(outcome, "earn|rent")

	gen 	numobs = string(NRF, "%12.0fc")
		
	gen geo = "n"

	keep geo outcome num*
		
	tempfile nycnumbers
	save `nycnumbers'
 
*** PREPARE COOK DATA
import delimited "${Inputs}\Cook_judgestringency_regs_ivols.csv", clear

	replace time_period = subinstr(time_period, "-", "_b", .)
	replace time_period = subinstr(time_period, " to ", "_", .)
	replace time_period = subinstr(time_period, "__b", "to", .)
	replace outcome = outcome + time_period 
	drop time_period 
	
	replace data = lower(data)

	replace outcome = "earn12" if outcome=="earn_b12to9"
	replace outcome = "earn8" if outcome=="earn_b8to1"
	replace outcome = "eshu1" if outcome=="n_em_shelter_b1"
	replace outcome = "home1" if outcome=="n_shelter_b1"
	replace outcome = "adda" if outcome=="ad_damnum"
	replace outcome = "hisp" if outcome=="hispanic"
	replace outcome = "nopr" if outcome=="noprior"
	replace outcome = "join" if outcome=="joint"
	replace outcome = "blac" if outcome=="black"
	replace outcome = "povr" if outcome=="nbrhd_pov_rate_5yr" & data=="lehd"
	replace outcome = "rent" if outcome=="nbrhd_med_rent_5yr" & data == "lehd"
	replace outcome = "rent2" if outcome=="avg_median_rent_b2to1"
	replace outcome = "rent4" if outcome=="avg_median_rent_b4to3"
	replace outcome = "povr2" if outcome=="avg_pov_rate_b2to1"
	replace outcome = "povr4" if outcome=="avg_pov_rate_b4to3"
	replace outcome = "move2" if outcome=="not_at_evic_b2to1"
	replace outcome = "move4" if outcome=="not_at_evic_b4to3"	
		
	gen zscore = eviction_coeff / eviction_se 
	gen pvalue=2*(1-normal(abs(zscore))) 

	gen 	stars = "***" if pvalue < 0.01
	replace stars = "**" if pvalue < 0.05 & mi(stars)
	replace stars = "*" if pvalue < 0.1 & mi(stars)

	gen 	numcoef = string(eviction_coeff, "%12.4fc") + stars
	replace numcoef = string(eviction_coeff, "%12.1fc") + stars if regexm(outcome, "earn|rent")

	gen 	numse = "(" + string(eviction_se, "%12.4fc") + ")"
	replace numse = "(" + string(eviction_se, "%12.1fc") + ")" if regexm(outcome, "earn|rent")

	gen 	nummean = string(non_evicted_mean, "%12.4fc")
	replace	nummean = string(non_evicted_mean, "%12.1fc") if regexm(outcome, "earn|rent")

	gen 	nummse = "(" + string(non_evicted_std_dev, "%12.4fc") + ")"
	replace	nummse = "(" + string(non_evicted_std_dev, "%12.1fc") + ")" if regexm(outcome, "earn|rent")

	gen 	numobs = string(observations, "%12.0fc")

	gen geo = "c"

	keep geo outcome num* 


** COMBINE AND SAVE LOCALS	
append using `nycnumbers'
reshape long num, i(outcome geo) j(detail) string

isid geo outcome detail

levelsof geo, local(geos) 
levelsof outcome, local(outcomes)
levelsof detail, local(details)

foreach gex in `geos' {
	local id0 = "`gex'"
	
	foreach outx in `outcomes' {
		local id1 = "`outx'"
		
		foreach detx in `details' {
			local id2 = "`detx'"
				
				levelsof num if geo=="`gex'" & ///
								outcome=="`outx'" & ///
								detail=="`detx'", ///
					clean local(`id0'_`id1'_`id2')
					di "`id0'_`id1'_`id2'"			
								
			}
		}
}


// to start off lines without errors
gl x " "
 
texdoc init "${Outputs}/Supplementary data_Table_G4.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c c c c} \hline \toprule ///
	& \multicolumn{2}{c}{\textbf{Cook}} & & \multicolumn{2}{c}{\textbf{New York}} \\
tex \cmidrule{2-3} \cmidrule{5-6}
tex	& {\scriptsize $ E[Y \vert E=0]$} & RF & & {\scriptsize $ E[Y \vert E=0]$} & RF \\
tex & (1) & (2) & & (3) & (4) \\
tex \cmidrule{2-3} \cmidrule{5-6}

tex \textbf{\underline{Lagged Outcomes}} & & \\

tex $x ~~Earnings (1-8 quarters before filing) 	& `c_earn8_mean' & `c_earn8_coef' 					& & `n_earn8_mean' & `n_earn8_coef' \\ 
tex 											& `c_earn8_mse' & `c_earn8_se' 						& & `n_earn8_mse' & `n_earn8_se' \\
tex 											& \multicolumn{2}{r}{[`c_earn8_obs']} 				& & \multicolumn{2}{r}{[`n_earn8_obs']} \\
tex \addlinespace
tex $x ~~Earnings (9-12 quarters before filing) & `c_earn12_mean' & `c_earn12_coef' 				& & `n_earn12_mean' & `n_earn12_coef' \\ 
tex 											& `c_earn12_mse' & `c_earn12_se' 					& & `n_earn12_mse' & `n_earn12_se' \\
tex 											& \multicolumn{2}{r}{[`c_earn12_obs']} 				& & \multicolumn{2}{r}{[`n_earn12_obs']} \\
tex \addlinespace
tex $x ~~Emergency Shelter (1 year before filing)	& `c_eshu1_mean' & `c_eshu1_coef' 				& & `n_eshu1_mean' & `n_eshu1_coef' \\ 
tex 												& `c_eshu1_mse' & `c_eshu1_se' 					& & `n_eshu1_mse' & `n_eshu1_se' \\
tex 												& \multicolumn{2}{r}{[`c_eshu1_obs']} 			& & \multicolumn{2}{r}{[`n_eshu1_obs']} \\
tex \addlinespace
tex $x ~~Any homelessness services (1 year before filing)	& `c_home1_mean' & `c_home1_coef' 		& & `n_home1_mean' & `n_home1_coef' \\ 
tex 														& `c_home1_mse' & `c_home1_se' 			& & `n_home1_mse' & `n_home1_se' \\
tex 														& \multicolumn{2}{r}{[`c_home1_obs']} 	& & \multicolumn{2}{r}{[`n_home1_obs']} \\
tex \addlinespace
tex $x ~~Not at eviction address (1-2 years before filing)	& `c_move2_mean' & `c_move2_coef' 		& & `n_move2_mean' & `n_move2_coef' \\ 
tex 														& `c_move2_mse' & `c_move2_se' 			& & `n_move2_mse' & `n_move2_se' \\
tex 														& \multicolumn{2}{r}{[`c_move2_obs']} 	& & \multicolumn{2}{r}{[`n_move2_obs']} \\
tex \addlinespace
tex $x ~~Neighborhood poverty rate (1-2 years before filing)	& `c_povr2_mean' & `c_povr2_coef' 	& & `n_povr2_mean' & `n_povr2_coef' \\ 
tex 														& `c_povr2_mse' & `c_povr2_se' 			& & `n_povr2_mse' & `n_povr2_se' \\
tex 														& \multicolumn{2}{r}{[`c_povr2_obs']} 	& & \multicolumn{2}{r}{[`n_povr2_obs']}  \\

tex \midrule 
tex \textbf{\underline{Demographic Characteristics}} & & \\

tex $x ~~Female		& `c_fem_mean' & `c_fem_coef' 					& & `n_fem_mean' & `n_fem_coef' \\ 
tex 				& `c_fem_mse' & `c_fem_se' 						& & `n_fem_mse' & `n_fem_se' \\
tex 				& \multicolumn{2}{r}{[`c_fem_obs']} 			& & \multicolumn{2}{r}{[`n_fem_obs']} \\
tex \addlinespace
tex $x ~~Black		& `c_blac_mean' & `c_blac_coef' 				& & `n_blac_mean' & `n_blac_coef' \\ 
tex 				& `c_blac_mse' & `c_blac_se' 					& & `n_blac_mse' & `n_blac_se'  \\
tex 				& \multicolumn{2}{r}{[`c_blac_obs']}		 	& & \multicolumn{2}{r}{[`n_blac_obs']} \\
tex \addlinespace
tex $x ~~Hispanic	& `c_hisp_mean' & `c_hisp_coef' 				& & `n_hisp_mean' & `n_hisp_coef' \\ 
tex 				& `c_hisp_mse' & `c_hisp_se' 					& & `n_hisp_mse' & `n_hisp_se' \\
tex 				& \multicolumn{2}{r}{[`c_hisp_obs']} 			& & \multicolumn{2}{r}{[`n_hisp_obs']} \\
tex \addlinespace
tex $x ~~Ad damnum (1000s)	& `c_adda_mean' & `c_adda_coef' 		& & `n_adda_mean' & `n_adda_coef' \\ 
tex 						& `c_adda_mse' & `c_adda_se' 			& & `n_adda_mse' & `n_adda_se'  \\
tex 						& \multicolumn{2}{r}{[`c_adda_obs']} 	& & \multicolumn{2}{r}{[`n_adda_obs']} \\
tex \addlinespace
tex $x ~~Joint action	& `c_join_mean' & `c_join_coef' 			& & `n_join_mean' & `n_join_coef'  \\ 
tex 					& `c_join_mse' & `c_join_se' 				& & `n_join_mse' & `n_join_se'  \\
tex 					& \multicolumn{2}{r}{[`c_join_obs']} 		& & \\
tex \addlinespace
tex $x ~~No prior	& `c_nopr_mean' & `c_nopr_coef' 				& & `n_nopr_mean' & `n_nopr_coef' \\ 
tex 				& `c_nopr_mse' & `c_nopr_se' 					& & `n_nopr_mse' & `n_nopr_se'  \\
tex 				& \multicolumn{2}{r}{[`c_nopr_obs']} 			& & \multicolumn{2}{r}{[`n_nopr_obs']} \\


tex \bottomrule \\
tex	\end{tabular} }
texdoc close

